package com.medicine.manage.block.service;

import com.medicine.manage.block.WeBASEUtils;
import com.medicine.manage.block.entity.WeBaseResult;
import com.medicine.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public abstract class AbstractBlockUpdateService<T> extends AbstractBlockService<T> implements IBlockUpdateService<T> {

    @Autowired
    private IUserExtendService userExtendService;

    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private WeBASEUtils weBASEUtils;

    @Override
    public WeBaseResult update(T obj, Long deptId, Long optionUserId, String functionName) {

        // 查询该煎药机构的合约address
        String contractAddress = deptService.getContractAddress(deptId);
        // 查询该操作员的address
        String userName = userExtendService.getSignUserName(optionUserId);
        // 准备智能合约订单插入方法所需参数
        List<String> list = new ArrayList<>();
        String param = this.createParam(obj, optionUserId);
        list.add(param);

        String string = weBASEUtils.funcPost(userName,contractAddress,functionName, list);
        WeBaseResult weBaseResult = weBASEUtils.convertResult(string);

        return weBaseResult;
    }
}
